<!DOCTYPE html>
<html lang="zh-cn">
<head>
    <title>项目列表</title>
    <?php PrintPageHead(); ?>
    <link href="../resource/css/hermes.css" rel="stylesheet">
    <link href="../resource/js/calendar/calendar-blue.css" type="text/css" rel="stylesheet">
    <script src="../resource/js/calendar/calendar.js" type="text/javascript"></script>
    <script src="../resource/js/hermes.js"></script>
    <style type="text/css">
       .form_d{
           width:500px;
           margin: 20px auto;
       }
    </style>
    <?php
    if (!array_key_exists("公众号ID",$_SESSION)) {
        header("Location:back.php");
    }
    $课程id ='';
    if(isset($_REQUEST['id']))$课程id = $_REQUEST['id'];
    if($课程id){
        $内容=pdo()->selectOne("SELECT a.*,b.`name`,c.`医院` FROM `语音课程`a LEFT JOIN `用户` b ON(a.`讲课专家id` =b.id) LEFT JOIN `医师详情` c ON(b.id = c.`用户id`)  WHERE  a.id=".$_REQUEST['id'].";");
    }
    $bm=new C后台管理员();
    $专家 = $bm->fc查找所有店长();


    ?>
</head>
<body>

<!-- 配置文件 -->
<script type="text/javascript" src="../ueditor/ueditor.config.js"></script>
<!-- 编辑器源码文件 -->
<script type="text/javascript" src="../ueditor/ueditor.all.min.js"></script>
<!-- 实例化编辑器 -->
<script type="text/javascript">
    var ue = UE.getEditor('container', {
        toolbars: [
            [ 'fullscreen', 'source', '|', 'undo', 'redo', '|',
                'bold', 'italic', 'underline', 'fontborder', 'strikethrough', 'superscript', 'subscript', 'removeformat', 'formatmatch', 'autotypeset', 'blockquote', 'pasteplain', '|', 'forecolor', 'backcolor', 'insertorderedlist', 'insertunorderedlist', 'selectall', 'cleardoc', '|',
                'rowspacingtop', 'rowspacingbottom', 'lineheight', '|',
                'customstyle', 'paragraph', 'fontfamily', 'fontsize', '|',
                'directionalityltr', 'directionalityrtl', 'indent', '|',
                'justifyleft', 'justifycenter', 'justifyright', 'justifyjustify', '|', 'touppercase', 'tolowercase', '|','link', 'unlink', 'anchor', '|', 'imagenone', 'imageleft', 'imageright', 'imagecenter', '|',
                'simpleupload', 'insertimage', 'emotion', 'scrawl', 'attachment', 'map', 'gmap', 'insertframe']
        ],
        autoHeightEnabled: true,
        autoFloatEnabled: true
    });
</script>

<div class="container-fluid">
    <?php include_once 'back_header.php'; ?>
    <div class="panel panel-primary">
        <div class="panel-heading text-center"><h3 class="panel-title"><?php if($内容['标题'])echo "编辑";else echo "添加";?>语音课程</h3></div>

        <div class="form_d">
            <form action="" method="post">
                昵称:<input type="text" name="name" id="namese" style="width: 120px">
                <input type="button" onclick="selectshow()" name="select" value="搜索用户">

            </form>
        </div>

        <form action="" method="post">
            <div class="form_d"><span style="width: 180px">用   户:</span>
                <div id="xianshi">
                    <?php  if($内容){?>
                        <input type="radio" checked="checked" value="<?=$内容['讲课专家id']?>" name="专家id">
                        <?=$内容['name']?>（<?=$内容['医院']?>）
                    <?php  }?>
                </div>
            <div class="form_d"><span>标题:</span><input type="text" name="title" value="<?=@$内容['title']?>"></div>

            <div class="form_d"><span>时间:</span>
            <input type="text" name="开始时间" placeholder="2016-01-12 20:00" value="<?=@$内容['开始时间']?>">~
                <input type="text" name="结束时间" placeholder="2016-01-12 22:00" value="<?=@$内容['结束时间']?>">
            </div>

            <div class="form_d"><span>简介:</span>
                <textarea name="简介" style="width: 90%"><?=@$内容['简介']?></textarea> </div>
            <div class="form_d"><span>内容:</span><!-- 加载编辑器的容器 -->
                <script id="container" name="content" type="text/plain"><?=@$内容['详情']?></script>
            </div>
            <div class="form_d"><input type="submit" name="okn" value="提交">  <a href="../back.php?state=back8Voice_LessonsS">查看历史</a> </div>
        </form>


    </div>


</div>

<!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
<script src="../resource/js/jquery-1.11.1.min.js"></script>
<!-- Include all compiled plugins (below), or include individual files as needed -->
<script src="../resource/js/bootstrap.min.js"></script>
<script language="JavaScript">
    function selectshow(){
        var name= document.getElementById("namese").value;
        $.post('back.php?state=BackSellerAjax',{name:name,'businessFlag':'ac查找用户'},function(data) {
            document.getElementById('xianshi').innerHTML='';
            document.getElementById("xianshi").innerHTML=data;

        });

    }
</script>
</body>
</html>
<?php
if(isset($_POST['okn'])){




    if($_REQUEST['title']==''||$_REQUEST['content']==''){
        echo "<script>alert('请认真填写信息!');</script>";
    }else if($_REQUEST['专家id']==''){
        echo "<script>alert('请认真选择讲课专家!');</script>";
    }else{

        $重复上课 = $bm->fc判断当前时间内专家有课($_REQUEST['专家id'],$_REQUEST['开始时间'],$_REQUEST['结束时间'],$课程id);
        if($重复上课>0){
            echo "<script>alert('该专家已有安排');</script>";
        }else{
            if($课程id){
                $dos= new  Do语音课程();
                $dos->set_id($_REQUEST['id']);
                $dos->set_title($_REQUEST['title']);
                $dos->set_详情($_REQUEST['content']);
                $dos->set_简介($_REQUEST['简介']);
                $dos->set_开始时间($_REQUEST['开始时间']);
                $dos->set_结束时间($_REQUEST['结束时间']);
                $dos->set_讲课专家id($_REQUEST['专家id']);
                $re= $dos->update();
                pdo()->update('语音课程报名',array('用户id'=>$_REQUEST['专家id']),array('课程id'=>$_REQUEST['id'],'专家'=>'是'));

                if($re){
                    $bm->fc发送图文消息_所有用户('语音课程',$_REQUEST['title'],$_REQUEST['id'],'Seller17Voice_Lessons');

                    echo "<script>alert('修改成功');location.replace(location.href);</script>";
                }else{
                    echo "<script>alert('修改失败或没有修改任何信息');</script>";
                }
            }else{
                $re = pdo()->insert('语音课程',array('id'=>$_REQUEST['id'],'title'=>$_REQUEST['title'],'详情'=>$_REQUEST['content'],'简介'=>$_REQUEST['简介'],'开始时间'=>$_REQUEST['开始时间'],'结束时间'=>$_REQUEST['结束时间'],'讲课专家id'=>$_REQUEST['专家id'],'type'=>'语音'));
                $课程id = pdo()->lastInsertId();
                $do报名 = new Do语音课程报名();
                $do报名->set_专家('是');
                $do报名->set_用户id($_REQUEST['专家id']);
                $do报名->set_课程id($课程id);
                $报名 = $do报名->insert();
                if($re &&$报名){
                    $bm->fc发送图文消息_所有用户('语音课程',$_REQUEST['title'],$课程id,'Seller17Voice_Lessons');
                    echo "<script>alert('添加成功');</script>";
                }else{
                    echo "<script>alert('添加失败');</script>";
                }
            }
        }



    }

}
?>
